import React, {Component} from "react";
import {fromJS, is} from "immutable";
import {Toast, WhiteSpace, WingBlank, Button} from 'antd-mobile';

export class BaseComponent extends Component {


    shouldComponentUpdate(nextProps, nextState) {
        return !is(fromJS(this.props), fromJS(nextProps)) || !is(fromJS(this.state), fromJS(nextState))
    }

    constructor() {
        super();
        console.log(this.prototype);
        this.handleChange = this.handleChange.bind(this);
    }




    showToast=(msg)=>{
        Toast.info(msg, 1);
    };

    showToastNoMask=(msg)=>{
        Toast.info(msg, 2, null, false);
    };

    showSuccessToast=(msg)=>{
        Toast.success(msg, 1);
    };


    showFailToast=(msg)=> {
        Toast.fail(msg, 1);
    };



    showOffline=(msg)=>{
        Toast.offline(msg, 1);
    };


    showLoadingToast=(msg,callback)=>{
        Toast.loading(msg, 1, () => {
            callback();
        });
    };


    handleChange(event) {
        const target = event.target;
        console.log(target);
        target.type = target.type || 'text';
        const value = target.type === 'checkbox' ? target.checked : target.value;
        const name = target.name;

        this.setState({
            [name]: value
        });
    }


}

